package org.grow.secure.controller;

import org.grow.secure.entity.enums.ApplyState;
import org.grow.secure.entity.enums.AuditState;
import org.grow.secure.entity.enums.LeaveType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Author: xwg
 * @CreateDate: 21-7-19
 */

@RestController
public class CommonController {
    @GetMapping("/basic/LeaveTypes")
    public List<Map<String, Object>> leaveTypes() {
        LeaveType[] values = LeaveType.values();
        return Arrays.stream(values)
                .map(x -> {
                    Map<String, Object> y = new HashMap<>();
                    y.put("index", x.ordinal());
                    y.put("text", x.getText());
                    y.put("value", x.name());
                    return y;
                }).collect(Collectors.toList());
    }
    @GetMapping("/basic/ApplyStates")
    public List<Map<String, Object>> applyStates() {

        return Arrays.stream(ApplyState.values())
                .map(x -> {
                    Map<String, Object> y = new HashMap<>();
                    y.put("index", x.ordinal());
                    y.put("text", x.getText());
                    y.put("value", x.name());
                    return y;
                }).collect(Collectors.toList());
    }
    @GetMapping("/basic/AuditStates")
    public List<Map<String, Object>> auditStates() {

        return Arrays.stream(AuditState.values())
                .map(x -> {
                    Map<String, Object> y = new HashMap<>();
                    y.put("index", x.ordinal());
                    y.put("text", x.getText());
                    y.put("value", x.name());
                    return y;
                }).collect(Collectors.toList());
    }

}
